{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 创造最大的数\n",
    "\n",
    "[![Author](https://img.shields.io/badge/Author-%40mjd507-important?style=social&logo=GitHub)](https://github.com/mjd507)\n",
    "[![WeChat Channel](https://img.shields.io/badge/Wechat-Daily%20Problem-important?style=social&logo=WeChat)](https://mp.weixin.qq.com/s/qi2c-bvHTSMzhu5B-78I_g)\n",
    "\n",
    "![Logo](img/Day82-1.png)\n",
    "\n",
    "　　给定一组整数，将它们拼在一起、创造出最大的数。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 用例说明\n",
    "\n",
    "```python\n",
    "In[1]:  [17, 7, 2, 45, 72]\n",
    "Out[1]:  77245217\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "def largestNum(nums: list) -> str:\n",
    "    for i in range(len(nums) - 1):\n",
    "        for j in range(i + 1, len(nums)):\n",
    "            a = int(str(nums[i]) + str(nums[j]))\n",
    "            b = int(str(nums[j]) + str(nums[i]))\n",
    "            if a < b:\n",
    "                (nums[i], nums[j]) = (nums[j], nums[i])\n",
    "    return ''.join([str(num) for num in nums])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "77245217\n"
     ]
    }
   ],
   "source": [
    "print(largestNum([17, 7, 2, 45, 72]))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
